package com.demo.Test;


import java.security.MessageDigest;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.params.HttpMethodParams;



public class UserRecharge {
	public static String HKMD5( String inStr)throws Exception
	  {
	    MessageDigest md5 = null;
	    try {
	      md5 = MessageDigest.getInstance("MD5");
	    } catch (Exception e) {
	      System.out.println(e.toString());
	      e.printStackTrace();
	    }
	    char[] charArray = inStr.toCharArray();
	    byte[] byteArray = new byte[charArray.length];

	    for (int i = 0; i < charArray.length; ++i) {
	      byteArray[i] = (byte)charArray[i];
	    }
	    byte[] md5Bytes = md5.digest(byteArray);

	    StringBuffer hexValue = new StringBuffer();

	    for (int i = 0; i < md5Bytes.length; ++i) {
	      int val = md5Bytes[i] & 0xFF;
	      if (val < 16)
	        hexValue.append("0");
	      hexValue.append(Integer.toHexString(val));
	    }
	    String outStr=hexValue.toString();
	    return outStr;
	  }
	public static void main(String[] args) {
		String info = null;
		try{
			HttpClient httpclient = new HttpClient();
			PostMethod post = new PostMethod("http://211.162.68.169/user/UserRecharge.tran");//
			post.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET,"UTF-8");
			post.addParameter("MERNO", "00000000000094");
			post.addParameter("ORDNO", "023000000000094");
			post.addParameter("CUSTNO", "00000100000096");
			post.addParameter("PAYACNO", "0000010000009601");
			post.addParameter("TXAMT", "100");
			post.addParameter("ORDTIME", "20150327163522");
			post.addParameter("NOTIFYURL", "https://www.baidu.com/");
			String str="MERNO=00000000000094&ORDNO=023000000000094&CUSTNO=00000100000096&PAYACNO=0000010000009601&TXAMT=100&ORDTIME=20150327163522&NOTIFYURL=https://www.baidu.com/"+"nqkHwgkRdWy5";
			System.out.println("加密前参数=="+str);
			post.addParameter("SIGNDATA", HKMD5(str));
			System.out.println("加密后参数=="+HKMD5(str));
			int httpcode=httpclient.executeMethod(post);
			System.out.println("httpcode---->"+httpcode);
			info = new String(post.getResponseBody(),"UTF-8");
			System.out.println("info---->"+info);
		}catch (Exception e) {
			e.printStackTrace();
		}
		
	}

	
}
